#!/usr/bin/perl -w
#
# $Id: InfoBox.pm,v 1.22 2003/07/23 04:22:40 solovam Exp $
#
# This file is a part of gkismet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

#
# InfoBox class
#
package InfoBox;

use Gtk;
use Misc;
use ReusableConnObserver;
use strict;
@InfoBox::ISA = qw(ReusableConnObserver);

#
# Constructor
#
sub new
{
	my $type = shift;
	my $self = new ReusableConnObserver(@_);
	bless $self, $type;

	my $frame = new Gtk::Frame(undef);
	$self->{'frame'} = $frame;
	$frame->set_label($self->getTitle());
	my $vbox = new Gtk::VBox($false, 5);
	$frame->add($vbox);

	for my $l ($self->getLabels())
	{
		my $hbox = new Gtk::HBox($false, 1);

		my $nlabel = new Gtk::Label($l . ': ');
		$nlabel->set_justify('left');
		$hbox->pack_start($nlabel, $false, $false, 5);

		my $vlabel = new Gtk::Label('');
		$vlabel->set_justify('right');
		$hbox->pack_end($vlabel, $false, $false, 5);

		$vbox->pack_start($hbox, $false, $false, 3);
	
		$self->{'label'}{$l} = $vlabel;
	}
	$frame->show_all();

	return $self;
}

#
# Remove all stored data
#
sub flush
{
	my $self = shift;
	for my $l ($self->getLabels())
	{
		$self->{'label'}{$l}->set_text('');
	}
}

#
# Handle an update from an observable
#
sub update
{
	my $self = shift;
	my $object = shift;
	my $data = shift;

	if($object->isa('Connection') && defined $self->{'connection'} && $self->{'connection'} eq $object)
	{
		if($self->isInterestingUpdate($data))
		{
			for my $l ($self->getLabels())
			{
				$self->{'label'}{$l}->set_text($self->getValue($l));
			}
		}
	}
}

#
# Get Gtk widget
#
sub getWidget
{
	my $self = shift;
	return($self->{'frame'});
}

1;
